//https://leetcode.cn/problems/wtcaE1/submissions/564730123/
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        if(s.size()==1)
        return 1;
        int max = 0;
        for (int i = 0,j=1,k=i; j<s.size();++j )
        {
            while(i<j)
            {
                if (s[j] == s[i])
                    break;
                ++i;
            }
            if (i == j)
            {
                if (max < j - k+1)
                    max = j - k+1;
                i = k;
            }
            else
            {
                k++;
                i = k;
                j -= 1;
                continue;
            }            
        }
        return max;
    }
};
